package zondy.yapi.extProject.util;

/**
 * 文本处理工具类
 *
 * @author 管子
 * @date 2024/7/31 22:41
 * @description: TextUtils 类
 */
public class TextUtils {

    /**
     * 处理<a></a>标签内容
     */
    public static String clearBracket(String context, char left, char right) {
        int head = context.indexOf(left);
        if (head == -1) {
            return context;
        } else {
            int next = head + 1;
            int count = 1;
            do {
                if (context.charAt(next) == left) {
                    count++;
                } else if (context.charAt(next) == right) {
                    count--;
                }
                next++;
                if (count == 0) {
                    String temp = context.substring(head, next);
                    context = context.replace(temp, "");
                    head = context.indexOf(left);
                    next = head + 1;
                    count = 1;
                }
            } while (head != -1);
        }
        return context.replaceAll("\\n", "").replaceAll(" +", " ");
    }

}
